package org.hilo.boot.scaffold;

/**
 * 
 * @author zollty
 * @since 2020年8月24日
 */
public class ScaffoldGeneratorMultiModule extends ScaffoldGenerator {
    
    protected static final String SOURCE_FILE_URL = "http://10.2.10.51:8081/nexus/content/repositories/releases/"
            + "org/hilo/framework/hilodemo-multi-source/1/hilodemo-multi-source-1.zip";
    protected static final String SOURCE_PROJECT_NAME = "hilodemo-multi";

    public ScaffoldGeneratorMultiModule() {
        super();
        this.sourceFileUrl = SOURCE_FILE_URL;
        sourceProjectName = SOURCE_PROJECT_NAME;
    }

    public ScaffoldGeneratorMultiModule(String groupId, String artifactId, String basePackage) {
        super(groupId, artifactId, basePackage);
        this.sourceFileUrl = SOURCE_FILE_URL;
        sourceProjectName = SOURCE_PROJECT_NAME;
    }
    
    @Override
    protected String starterProjectPath() {
        return targetBasePath + artifactId + "-assembly/";
    }
    
    @Override
    protected String bizProjectPath() {
        return targetBasePath + artifactId + "-integration/";
    }
    
    @Override
    public byte[] generatorFile() {
        this.separateBizApp = true;
        this.useType = ScaffoldGenerator.TYPE_DUBBO;
        return super.generatorFile();
    }
    
    @Override
    void commonBuild(String target) {
        deleteAll(target + artifactId + "-app/");
        deleteIDEFiles(target);
        deleteIDEFiles(target + artifactId + "-assembly/");
        deleteIDEFiles(target + artifactId + "-facade/");
        deleteIDEFiles(target + artifactId + "-biz/");
        deleteIDEFiles(target + artifactId + "-integration/");
        deleteIDEFiles(target + artifactId + "-dal/");
        deleteIDEFiles(target + artifactId + "-common/");
        deleteIDEFiles(target + artifactId + "-api/");
        
        Rep.build(starterProjectPath() + "src/main/resources/META-INF/app.properties", null)
        .replace("fast4ui", artifactId).apply();
        
        Rep.build(starterProjectPath() +"src/main/resources/application.yml", null)
        .replace("hilo-demo", artifactId)
        .replace(EXA_PACKAGE, basePackage)
        .apply();
        
        Rep.build(starterProjectPath() + "src/main/resources/application-dubbo.yml", null)
        .replace("hilo-demo", artifactId).apply();

    }
    
    @Override
    void buildDubbo(String target, String newPath) {
        
    }
    
    @Override
    void buildAdmin(String target, String newPath) {
        
    }
    
//    @Override
//    // 往pom.xml等标准文件中添加组件
//    void pluginBuild(String target, PluginGenerator plugin) {
//        
//        String ext = plugin.addParentPomManagementDependency();
//        if (UT.Str.isNotEmpty(ext)) {
//            Rep.build(target + "pom.xml", null)
//                .replace("    </dependencies>", ext + "\r\n    </dependencies>")
//                .apply();
//        }
//        
//        
//        ext = plugin.addStarterPomManagementDependency();
//        if (UT.Str.isNotEmpty(ext)) {
//            Rep.build(starterProjectPath() + "pom.xml", null)
//                .replace("  </dependencies>", ext + "\r\n  </dependencies>")
//                .apply();
//        }
//        ext = plugin.addBizPomManagementDependency();
//        if (UT.Str.isNotEmpty(ext)) {
//            Rep.build(bizProjectPath() + "pom.xml", null)
//                .replace("  </dependencies>", ext + "\r\n  </dependencies>")
//                .apply();
//        }
//        
//        ext = plugin.addDevYamlConfig();
//        if (UT.Str.isNotEmpty(ext)) {
//            Rep.build(starterProjectPath() + "src/main/resources/application-dev.yml", null)
//                .append(ext)
//                .apply();
//        }
//        
//    }
    
    static final String WAR_DEP = "<!-- starter-test = junit + spring-test + mockito -->\r\n    <dependency>\r\n      <groupId>org.springframework.boot</groupId>\r\n      <artifactId>spring-boot-starter-test</artifactId>\r\n      <scope>test</scope>\r\n    </dependency>\r\n    \r\n    <!-- starter-web = spring-webmvc + logback + tomcat -->\r\n    <dependency>\r\n      <groupId>org.springframework.boot</groupId>\r\n      <artifactId>spring-boot-starter-web</artifactId>\r\n      <exclusions>\r\n        <!-- war包部署，将默认的tomcat依赖改成provided -->\r\n        <exclusion>\r\n          <groupId>org.springframework.boot</groupId>\r\n          <artifactId>spring-boot-starter-tomcat</artifactId>\r\n        </exclusion>\r\n      </exclusions>\r\n    </dependency>\r\n    <dependency>\r\n      <groupId>org.springframework.boot</groupId>\r\n      <artifactId>spring-boot-starter-tomcat</artifactId>\r\n      <scope>provided</scope>\r\n    </dependency>\r\n    <dependency>\r\n      <groupId>org.apache.tomcat</groupId>\r\n      <artifactId>tomcat-jdbc</artifactId>\r\n      <scope>provided</scope>\r\n    </dependency>\r\n    <!-- end starter-web -->";
    static final String EXA_PACKAGE = "io.hilo.example";
    
}
